<?php
class abms extends controller
{
	private $t = null;
	public function __construct( & $plantilla)
	{
		//$plantilla->assign('TITLE','Listando los alimentos');
		$this->t = & $plantilla;
	}
	public function delete_animal_seccion($id = 0)
	{
		$DATOS = DB::SELECT('animal_seccion','*','WHERE seccion_id=?')->set($id)->fetch(DB::FETCH_ASSOC);
		if(!empty($_POST['delete']) && !empty($_POST['delete']['id'])) {
			$ID = intval($_POST['delete']['id']);
			if($ID > 0)
			{
				$consulta = DB::delete('animal_seccion','WHERE seccion_id=?')->set($ID);
				if($consulta->rowCount()>0)
				{
					$msg = 'SE borro Correctamente '.  $DATOS['nombres'];
				}
			}
			echo empty($msg)? 'UN ERROR A OCURRIDO : ' . implode("<br />\n --", $consulta->errorinfo()) :$msg;
		}
		else
		{
			$this->t->parse('formulario/delete');
				$this->t->assign('title','Esta seguro de esta seccion' . $DATOS['nombres'])
				->assign('id',$id);
		 	echo $this->t->render();
		}
		die();
	}
	public function delete_clase($id = 0)
	{
		/*$DATOS = DB::SELECT('clase','*','WHERE id_clase=?')->set($id)->fetch(DB::FETCH_ASSOC);
		if(!empty($_POST['delete']) && !empty($_POST['delete']['id'])) {
			$ID = intval($_POST['delete']['id']);
			//$msg = 'UN ERROR A OCURRIDO';
			if($ID > 0){
				$consulta = DB::delete('clase','WHERE id_clase=?')->set($ID);
				if($consulta->rowCount()>0)
				{
					$msg = 'SE Elimino el tipo Correctamente '. $DATOS['name'];
				}
			}
			echo empty($msg)? 'UN ERROR A OCURRIDO : ' . implode("<br />\n --", $consulta->errorinfo()) :$msg;
		}
		else
		{
			$this->t->parse('formulario/delete');
				$this->t->assign('title','Esta seguro de borrar ' . $DATOS['name'])
						->assign('id',$id);
		 	echo $this->t->render();
		}
		 die();/**/
		 $this->delete_global($id,'clase','id_clase','name');
	}
	public function delete_regiones($id = 0)
	{
		$this->delete_global($id,'regiones','id_region','region_name');
	}public function delete_platos($id = 0)
	{
		$this->delete_global($id,'platos','id_plato','name');
	}
	public function delete_global($id = 0,$table,$key_name,$field_name_show)
	{
		$DATOS = DB::SELECT($table,'*','WHERE '.$key_name.'=?')->set($id)->fetch(DB::FETCH_ASSOC);
		if(!empty($_POST['delete']) && !empty($_POST['delete']['id'])) {
			$ID = intval($_POST['delete']['id']);
			//$msg = 'UN ERROR A OCURRIDO';
			if($ID > 0){
				$consulta = DB::delete($table,'WHERE '.$key_name.'=?')->set($ID);
				if($consulta->rowCount()>0)
				{
					$msg = 'SE Elimino el tipo Correctamente '. $DATOS[$field_name_show];
				}
			}
			echo empty($msg)? 'UN ERROR A OCURRIDO : ' . implode("<br />\n --", $consulta->errorinfo()) :$msg;
		}
		else
		{
			$this->t->parse('formulario/delete');
				$this->t->assign('title','Esta seguro de borrar ' . $DATOS[$field_name_show])
						->assign('id',$id);
		 	echo $this->t->render();
		}
		 die();
	}
	public function getDefault()
	{
		return "<h1>UPS se perdio??</h1>";
	}
	public function error404($metodo)
	{
		//return parent::error404($metodo);
		
		return 'Pagina no encontrada';
	}
}